package cn.edu.scau.cmi.zhuangzhihong.composite.consistence;

import java.util.ArrayList;
import java.util.List;

import cn.edu.scau.cmi.zhuangzhihong.composite.consistence.Component;

public class Composite implements Component{

	private String name;
	
	private List<Component> child = new ArrayList<Component>();
	
	public Composite(String name) {
		this.name=name;
	}
	
	@Override
	public StringBuilder printStruct(String Struct) {
		// TODO 自动生成的方法存根
		StringBuilder sb = new StringBuilder();
      sb.append(Struct+"+"+this.name+"\n");
      if(this.child!=null) {
    	  Struct +="  ";
    	  for(Component i:child) {
    		 sb.append(i.printStruct(Struct)) ;
    	  }
      }
      return sb;
	}
	
	public List<Component> getchild(){
		return child;
	}
	
	public void add(Component c) {
		child.add(c);
	}
	
	public void remove(int index) {
		child.remove(index);
	}

	
}
